package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);
    @Insert("insert into setmeal " +
            " (category_id,name,price,status,description,image,create_time,update_time,create_user,update_user)" +
            " values" +
            "(#{categoryId},#{name},#{price},#{status},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    @AutoFill(OperationType.INSERT)
    void saveSetmeal(Setmeal setmeal);

    /**
     * 分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 通过id查询套餐信息
     * @param id
     * @return
     */
    @Select("select * from setmeal where id=#{id}")
    Setmeal findById(int id);



    void deleteByIds(List<Integer> ids);

    /**
     * 更新操作
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     * 根据分类id查询套餐，返回集合
     * @param setmeal
     * @return
     */
    List<Setmeal> findSetmeal(Setmeal setmeal);

    List<DishItemVO> findSetmealDishes(Integer setmealId);

    @Select("select count(*) from setmeal where status=#{status}")
    Integer getTodayOverviewSetmeals(Integer disable);
}